/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       meshloader.cpp
 * Author:     twoja stara
 * Created on: 2009-05-31
 *
 **********************************************************************************************************************/

#include "meshloader.h"
#include "aseloader.h"
#include "objloader.h"
#include "ms3dloader.h"

namespace mGameEngine
{
namespace Graphics
{

Mesh *MeshLoader::loadMeshFromFile(const String &filename)
{
    MeshLoader ld(filename);
    ld.load();
    return ld.getMesh();
}

MeshLoader::MeshLoader() : MeshFactory(), FileLoader()
{
}

MeshLoader::MeshLoader(const String &filename) :
    MeshFactory(), FileLoader(filename)
{
}

MeshLoader::~MeshLoader()
{
}

void MeshLoader::load()
{
    // begin loading
    _state = 0.0f;

    if(_extension == "ase")
    {
        AseLoader loader(_filename);
        loader.load();
        _mesh = loader.getMesh();
    }
    else if(_extension == "obj")
    {
        OBJLoader loader(_filename);
        loader.load();
        _mesh = loader.getMesh();
    }
    else if(_extension == "ms3d")
    {
        MS3DLoader loader(_filename);
        loader.load();
        _mesh = loader.getMesh();
    }
    else
    {
        return;
    }

    // end loading
    _state = 1.0f;
}

void MeshLoader::unload()
{
    // no mesh loaded
    if(!_mesh)
    {
        _state = 0.0f;
        return;
    }

    // unload mesh
    delete _mesh;

    // finish unloading
    _state = 0.0f;
}

}

}

